package cn.txm.order.controller;

import cn.txm.basic.util.AjaxResult;
import cn.txm.basic.util.RedisUtils;
import cn.txm.order.domain.AdoptOrder;
import cn.txm.order.service.IAdoptOrderService;
import cn.txm.user.domain.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * 宠物领养订单接口
 * @author Administrator
 * @version 1.0
 * @date 2021/1/21 16:12
 */
@RestController
public class AdoptOrderController {

    @Autowired
    private IAdoptOrderService adoptOrderService;

    @PutMapping("/adoptOrder")
    public AjaxResult submitAdoptOrder(@RequestBody AdoptOrder adoptOrder, HttpServletRequest request){
        try {
            User user = RedisUtils.INSTANCE.getUser(request, User.class);
            adoptOrder.setUser(user);
            return adoptOrderService.submitAdoptOrder(adoptOrder);
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMessage("提交失败,我们正在殴打程序员"+e.getMessage());
        }
    }
}
